package org.example.domain;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.util.Date;
import java.util.List;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Book {
    public interface Save{};
    public interface Update{};

    @TableId("id")
    @NotNull(message = "书籍ID不能为空",groups = {Question.Update.class})
    @Null(message = "书籍ID必须为空",groups = {Question.Save.class})
    private Integer bookId;
    @NotNull(message = "名字不能为空",groups = {Save.class})
    private String name;
    private float price;
    @TableField(value = "is_free")
    private int isFree;
    @TableField(exist = false, select = false)
    private List<String> type;
    private String cover;
    @TableField(exist = false, select = false)
    private BookContent data;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time",fill = FieldFill.INSERT)
    private Date createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time",fill = FieldFill.UPDATE)
    private Date updateTime;
}
